/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LoginGUI.java
 *
 * Created on 10-06-2011, 16:52:57
 */
package GUILayer;
import ControlLayer.*;
import java.awt.Color;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import ModelLayer.*;
import javax.swing.JTable;
/**
 *
 * @author Jonas Kristensen
 */
public class MainMenuGUI extends javax.swing.JFrame {

    private LoginGUI loginGUI;
    private OrderController orderController;
    private PersonController personController;
    private SupplierController supplierController;
    private ItemController itemController;
    private int orderID;
    private JFrame controllingFrame; // needed for Errordialog
    private int row;
    private boolean setOrderNameCreated;
    private RentalController rentalCon;
    private String loginName;
    
    /** Creates new form LoginGUI */
    public MainMenuGUI(String loginName, LoginGUI login) {
        initComponents();
        loggedInAsLabel.setText("Logged in as: " + loginName);
        loginGUI = login;
        orderController = new OrderController();
        personController = new PersonController();
        supplierController = new SupplierController();
        itemController = new ItemController();
        OrderAndFindItemAndDeleteAndCancelButtonsFalse();
        saleCreateAndCancelButtonsFalse();
        row = 0;
        setOrderNameCreated = false;
        rentalCon = new RentalController();
        jPanel7.setVisible(false);
        this.loginName = loginName;
        checkLogin();
        //jButton4.setEnabled(false); //delete button for Person
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane4 = new javax.swing.JTabbedPane();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        barcodeItemNumberbuttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        logOutButton = new javax.swing.JButton();
        loggedInAsLabel = new javax.swing.JLabel();
        mainMenuPanel = new javax.swing.JPanel();
        tabSupplierPanel = new javax.swing.JTabbedPane();
        tabOrderPanel = new javax.swing.JPanel();
        tabOrderFindItemPanel = new javax.swing.JPanel();
        searchField = new javax.swing.JTextField();
        searchButton = new javax.swing.JButton();
        barcodeButton = new javax.swing.JRadioButton();
        itemNumberButton = new javax.swing.JRadioButton();
        itemDetailsLabel = new javax.swing.JLabel();
        findItemItemdetailsSeparator = new javax.swing.JSeparator();
        nameLabel = new javax.swing.JLabel();
        barcodeLabel = new javax.swing.JLabel();
        itemLabel = new javax.swing.JLabel();
        priceLabel = new javax.swing.JLabel();
        discountLabel = new javax.swing.JLabel();
        locationLabel = new javax.swing.JLabel();
        inStockLabel = new javax.swing.JLabel();
        customersNamePanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        orderTabel = new javax.swing.JTable();
        totalPriceLabel = new javax.swing.JLabel();
        totalPriceNoVATLabel = new javax.swing.JLabel();
        VATLabel = new javax.swing.JLabel();
        orderIDLabel = new javax.swing.JLabel();
        dateLabel = new javax.swing.JLabel();
        customersName1Label = new javax.swing.JLabel();
        createOrderButton = new javax.swing.JButton();
        deleteItemButton = new javax.swing.JButton();
        cancelOrderButton = new javax.swing.JButton();
        orderSentLabel = new javax.swing.JLabel();
        infoDeleteLabel = new javax.swing.JLabel();
        tabOrderEnterCustomersNamePanel = new javax.swing.JPanel();
        customersName1Field = new javax.swing.JTextField();
        customersNameButton = new javax.swing.JButton();
        noNameLabel = new javax.swing.JLabel();
        tabSalePanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        UnregistredButton = new javax.swing.JRadioButton();
        registredButton = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        idField = new javax.swing.JTextField();
        saleOKButton = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        saleOrderTabel = new javax.swing.JTable();
        saleTotalPriceNoVATLabel = new javax.swing.JLabel();
        saleVATLabel = new javax.swing.JLabel();
        saleTotalPriceLabel = new javax.swing.JLabel();
        saleCustomersNameLabel = new javax.swing.JLabel();
        saleOrderIDLabel = new javax.swing.JLabel();
        saleDateLabel = new javax.swing.JLabel();
        saleCancelOrderButton = new javax.swing.JButton();
        salePayButton = new javax.swing.JButton();
        saleStatusOnOrderLabel = new javax.swing.JLabel();
        saleStatusLabel = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        txtPhoneNo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        tabStockItemPanel = new javax.swing.JPanel();
        searchItemPanel3 = new javax.swing.JPanel();
        searchItemTextField2 = new javax.swing.JTextField();
        searchItemButton1 = new javax.swing.JButton();
        barcodeRadioButton1 = new javax.swing.JRadioButton();
        itemNumberRadioButton1 = new javax.swing.JRadioButton();
        showItemPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        ItemTable2 = new javax.swing.JTable();
        createItemButton1 = new javax.swing.JButton();
        updateItemButton1 = new javax.swing.JButton();
        deleteItemButton1 = new javax.swing.JButton();
        orderItemButton = new javax.swing.JButton();
        updateStockButton = new javax.swing.JButton();
        tabPersonPanel = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        findPersonButton = new javax.swing.JButton();
        jPhoneTxt = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tabRentMachines = new javax.swing.JPanel();
        seachButton1 = new javax.swing.JButton();
        machineListTextField1 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        machineListningjTable1 = new javax.swing.JTable();
        changeStatusButton2 = new javax.swing.JButton();
        updateMachineButton3 = new javax.swing.JButton();
        createMachineButton4 = new javax.swing.JButton();
        deleteMachineButton5 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        searchSupplierTextField3 = new javax.swing.JTextField();
        searchSupplierButton5 = new javax.swing.JButton();
        createSupplierButton5 = new javax.swing.JButton();
        updateSupplierAddressButton5 = new javax.swing.JButton();
        updateSupplierDeliveryPhoneButton5 = new javax.swing.JButton();
        deleteSupplierButton5 = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        supplierTable3 = new javax.swing.JTable();
        tabOrders = new javax.swing.JPanel();
        showAllOrdersButton = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        findOrdersTable = new javax.swing.JTable();
        ordersSearchPanel = new javax.swing.JPanel();
        ordersSearchTextfield = new javax.swing.JTextField();
        ordersSearchButton = new javax.swing.JButton();
        ordersIDButton = new javax.swing.JRadioButton();
        ordersCustomersNameButton = new javax.swing.JRadioButton();
        ordersDeleteButton = new javax.swing.JButton();
        ordersClearTableButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Vestbjerg Byggecenter");
        setResizable(false);

        logOutButton.setText("Logout");
        logOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logOutButtonActionPerformed(evt);
            }
        });

        loggedInAsLabel.setText("Logged in as:");

        mainMenuPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Main menu"));

        tabOrderFindItemPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Find item"));

        searchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchFieldActionPerformed(evt);
            }
        });

        searchButton.setText("Search");
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });

        buttonGroup1.add(barcodeButton);
        barcodeButton.setSelected(true);
        barcodeButton.setText("Barcode");
        barcodeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                barcodeButtonActionPerformed(evt);
            }
        });

        buttonGroup1.add(itemNumberButton);
        itemNumberButton.setText("Item number");
        itemNumberButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemNumberButtonActionPerformed(evt);
            }
        });

        itemDetailsLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        itemDetailsLabel.setText("Item details");

        findItemItemdetailsSeparator.setForeground(new java.awt.Color(0, 0, 0));

        nameLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        nameLabel.setText("Name:");

        barcodeLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        barcodeLabel.setText("Barcode:");

        itemLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        itemLabel.setText("Item nb:");

        priceLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        priceLabel.setText("Price:");

        discountLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        discountLabel.setText("Discount:");

        locationLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        locationLabel.setText("Location:");

        inStockLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        inStockLabel.setText("In stock:");

        javax.swing.GroupLayout tabOrderFindItemPanelLayout = new javax.swing.GroupLayout(tabOrderFindItemPanel);
        tabOrderFindItemPanel.setLayout(tabOrderFindItemPanelLayout);
        tabOrderFindItemPanelLayout.setHorizontalGroup(
            tabOrderFindItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                .addGroup(tabOrderFindItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(itemDetailsLabel)
                    .addGroup(tabOrderFindItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(findItemItemdetailsSeparator, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tabOrderFindItemPanelLayout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(tabOrderFindItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(searchField, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(searchButton))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(tabOrderFindItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(itemNumberButton)
                                .addComponent(barcodeButton))))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(barcodeLabel))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(itemLabel))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(nameLabel))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(locationLabel))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(inStockLabel))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(discountLabel))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(priceLabel)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tabOrderFindItemPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {barcodeLabel, discountLabel, inStockLabel, itemLabel, locationLabel, nameLabel, priceLabel});

        tabOrderFindItemPanelLayout.setVerticalGroup(
            tabOrderFindItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                .addGroup(tabOrderFindItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addComponent(barcodeButton)
                        .addGap(2, 2, 2)
                        .addComponent(itemNumberButton))
                    .addGroup(tabOrderFindItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(searchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(searchButton)))
                .addGap(18, 18, 18)
                .addComponent(itemDetailsLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(findItemItemdetailsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(barcodeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(itemLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(nameLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(locationLabel)
                .addGap(13, 13, 13)
                .addComponent(priceLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(discountLabel)
                .addGap(11, 11, 11)
                .addComponent(inStockLabel)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        customersNamePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Order"));

        orderTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Name", "Barcode", "Item number", "Location", "Amount", "Price/stc", "Total price"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        orderTabel.getTableHeader().setReorderingAllowed(false);
        orderTabel.setUpdateSelectionOnSort(false);
        orderTabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                orderTabelMouseClicked(evt);
            }
        });
        orderTabel.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                orderTabelComponentAdded(evt);
            }
            public void componentRemoved(java.awt.event.ContainerEvent evt) {
                orderTabelComponentRemoved(evt);
            }
        });
        orderTabel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                orderTabelKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(orderTabel);
        orderTabel.getColumnModel().getColumn(0).setResizable(false);
        orderTabel.getColumnModel().getColumn(0).setPreferredWidth(200);
        orderTabel.getColumnModel().getColumn(1).setResizable(false);
        orderTabel.getColumnModel().getColumn(2).setResizable(false);
        orderTabel.getColumnModel().getColumn(2).setPreferredWidth(50);
        orderTabel.getColumnModel().getColumn(3).setResizable(false);
        orderTabel.getColumnModel().getColumn(3).setPreferredWidth(50);
        orderTabel.getColumnModel().getColumn(4).setResizable(false);
        orderTabel.getColumnModel().getColumn(4).setPreferredWidth(30);
        orderTabel.getColumnModel().getColumn(5).setResizable(false);
        orderTabel.getColumnModel().getColumn(5).setPreferredWidth(50);
        orderTabel.getColumnModel().getColumn(6).setResizable(false);
        orderTabel.getColumnModel().getColumn(6).setPreferredWidth(50);

        totalPriceLabel.setText("Total Price:");

        totalPriceNoVATLabel.setText("Total price no VAT:");

        VATLabel.setText("VAT:");

        orderIDLabel.setText("Order ID:");

        dateLabel.setText("Date:");

        customersName1Label.setText("Customers name:");

        createOrderButton.setText("Create Order");
        createOrderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createOrderButtonActionPerformed(evt);
            }
        });

        deleteItemButton.setText("Delete item");
        deleteItemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteItemButtonActionPerformed(evt);
            }
        });

        cancelOrderButton.setText("Cancel Order");
        cancelOrderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelOrderButtonActionPerformed(evt);
            }
        });

        orderSentLabel.setOpaque(true);

        infoDeleteLabel.setFont(new java.awt.Font("Tahoma", 0, 10));
        infoDeleteLabel.setText("You can also delete an item by pressing 0 in \"Amount\"");

        javax.swing.GroupLayout customersNamePanelLayout = new javax.swing.GroupLayout(customersNamePanel);
        customersNamePanel.setLayout(customersNamePanelLayout);
        customersNamePanelLayout.setHorizontalGroup(
            customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customersNamePanelLayout.createSequentialGroup()
                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, customersNamePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, customersNamePanelLayout.createSequentialGroup()
                                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(customersName1Label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(dateLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(orderIDLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147, Short.MAX_VALUE)
                                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(totalPriceNoVATLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                                    .addComponent(VATLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(totalPriceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(customersNamePanelLayout.createSequentialGroup()
                                .addComponent(deleteItemButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 344, Short.MAX_VALUE)
                                .addComponent(cancelOrderButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(orderSentLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(createOrderButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGap(39, 39, 39))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 682, Short.MAX_VALUE)
                    .addGroup(customersNamePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(infoDeleteLabel)))
                .addContainerGap())
        );
        customersNamePanelLayout.setVerticalGroup(
            customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customersNamePanelLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalPriceNoVATLabel)
                    .addComponent(dateLabel))
                .addGap(13, 13, 13)
                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(orderIDLabel)
                    .addComponent(VATLabel))
                .addGap(11, 11, 11)
                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(customersName1Label)
                    .addComponent(totalPriceLabel))
                .addGap(11, 11, 11)
                .addComponent(orderSentLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(customersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteItemButton)
                    .addComponent(cancelOrderButton)
                    .addComponent(createOrderButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(infoDeleteLabel)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        tabOrderEnterCustomersNamePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Enter Customers name"));

        customersNameButton.setText("OK");
        customersNameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customersNameButtonActionPerformed(evt);
            }
        });

        noNameLabel.setFont(new java.awt.Font("Tahoma", 0, 10));
        noNameLabel.setText("No name? Just press OK");

        javax.swing.GroupLayout tabOrderEnterCustomersNamePanelLayout = new javax.swing.GroupLayout(tabOrderEnterCustomersNamePanel);
        tabOrderEnterCustomersNamePanel.setLayout(tabOrderEnterCustomersNamePanelLayout);
        tabOrderEnterCustomersNamePanelLayout.setHorizontalGroup(
            tabOrderEnterCustomersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrderEnterCustomersNamePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabOrderEnterCustomersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabOrderEnterCustomersNamePanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(noNameLabel))
                    .addGroup(tabOrderEnterCustomersNamePanelLayout.createSequentialGroup()
                        .addComponent(customersName1Field, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(customersNameButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        tabOrderEnterCustomersNamePanelLayout.setVerticalGroup(
            tabOrderEnterCustomersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrderEnterCustomersNamePanelLayout.createSequentialGroup()
                .addGroup(tabOrderEnterCustomersNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(customersNameButton)
                    .addComponent(customersName1Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(noNameLabel)
                .addContainerGap())
        );

        javax.swing.GroupLayout tabOrderPanelLayout = new javax.swing.GroupLayout(tabOrderPanel);
        tabOrderPanel.setLayout(tabOrderPanelLayout);
        tabOrderPanelLayout.setHorizontalGroup(
            tabOrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrderPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabOrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tabOrderEnterCustomersNamePanel, 0, 227, Short.MAX_VALUE)
                    .addComponent(tabOrderFindItemPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(customersNamePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(52, 52, 52))
        );
        tabOrderPanelLayout.setVerticalGroup(
            tabOrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrderPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabOrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(customersNamePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(tabOrderPanelLayout.createSequentialGroup()
                        .addComponent(tabOrderEnterCustomersNamePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tabOrderFindItemPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        tabSupplierPanel.addTab("Make order", tabOrderPanel);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Chose type of customer"));
        jPanel1.setPreferredSize(new java.awt.Dimension(233, 80));

        buttonGroup2.add(UnregistredButton);
        UnregistredButton.setSelected(true);
        UnregistredButton.setText("Unregistred");
        UnregistredButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UnregistredButtonActionPerformed(evt);
            }
        });

        buttonGroup2.add(registredButton);
        registredButton.setText("Registred");
        registredButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                registredButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(UnregistredButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(registredButton)
                .addContainerGap(28, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(UnregistredButton)
                    .addComponent(registredButton))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Type id on order"));

        saleOKButton.setText("Find");
        saleOKButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saleOKButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(idField, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
                    .addComponent(saleOKButton, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saleOKButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Sale"));

        saleOrderTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Name", "Barcode", "Item number", "Location", "Amount", "Manuel given discount", "Total price"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        saleOrderTabel.getTableHeader().setReorderingAllowed(false);
        saleOrderTabel.setUpdateSelectionOnSort(false);
        jScrollPane5.setViewportView(saleOrderTabel);
        saleOrderTabel.getColumnModel().getColumn(0).setResizable(false);
        saleOrderTabel.getColumnModel().getColumn(0).setPreferredWidth(180);
        saleOrderTabel.getColumnModel().getColumn(1).setResizable(false);
        saleOrderTabel.getColumnModel().getColumn(2).setResizable(false);
        saleOrderTabel.getColumnModel().getColumn(2).setPreferredWidth(50);
        saleOrderTabel.getColumnModel().getColumn(3).setResizable(false);
        saleOrderTabel.getColumnModel().getColumn(3).setPreferredWidth(50);
        saleOrderTabel.getColumnModel().getColumn(4).setResizable(false);
        saleOrderTabel.getColumnModel().getColumn(4).setPreferredWidth(30);
        saleOrderTabel.getColumnModel().getColumn(5).setResizable(false);
        saleOrderTabel.getColumnModel().getColumn(5).setPreferredWidth(100);
        saleOrderTabel.getColumnModel().getColumn(6).setResizable(false);
        saleOrderTabel.getColumnModel().getColumn(6).setPreferredWidth(50);

        saleTotalPriceNoVATLabel.setText("Total price no VAT:");

        saleVATLabel.setText("VAT:");

        saleTotalPriceLabel.setText("Total Price:");

        saleCustomersNameLabel.setText("Customers name:");

        saleOrderIDLabel.setText("Order ID:");

        saleDateLabel.setText("Date:");

        saleCancelOrderButton.setText("Cancel Order");
        saleCancelOrderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saleCancelOrderButtonActionPerformed(evt);
            }
        });

        salePayButton.setText("Pay");
        salePayButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salePayButtonActionPerformed(evt);
            }
        });

        saleStatusOnOrderLabel.setText("Status on order:");

        saleStatusLabel.setOpaque(true);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 731, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(saleCustomersNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
                                    .addComponent(saleOrderIDLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addComponent(saleDateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(saleVATLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(saleTotalPriceLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(saleTotalPriceNoVATLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(saleStatusOnOrderLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saleStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 265, Short.MAX_VALUE)
                .addComponent(saleCancelOrderButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(salePayButton)
                .addGap(17, 17, 17))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {saleCancelOrderButton, salePayButton});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saleDateLabel)
                    .addComponent(saleTotalPriceNoVATLabel))
                .addGap(13, 13, 13)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saleVATLabel)
                    .addComponent(saleOrderIDLabel))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saleCustomersNameLabel)
                    .addComponent(saleTotalPriceLabel))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(saleCancelOrderButton)
                        .addComponent(salePayButton))
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(saleStatusOnOrderLabel)
                        .addComponent(saleStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(50, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Attach Customer"));

        jLabel1.setText("Phone Number");

        jButton1.setText("Attach");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtPhoneNo, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPhoneNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout tabSalePanelLayout = new javax.swing.GroupLayout(tabSalePanel);
        tabSalePanel.setLayout(tabSalePanelLayout);
        tabSalePanelLayout.setHorizontalGroup(
            tabSalePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabSalePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabSalePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50))
        );
        tabSalePanelLayout.setVerticalGroup(
            tabSalePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabSalePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabSalePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(tabSalePanelLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        tabSupplierPanel.addTab("Sale", tabSalePanel);

        searchItemPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Enter barcode or item number"));

        searchItemButton1.setText("Search");
        searchItemButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchItemButton1ActionPerformed(evt);
            }
        });

        barcodeItemNumberbuttonGroup3.add(barcodeRadioButton1);
        barcodeRadioButton1.setSelected(true);
        barcodeRadioButton1.setText("barcode");

        barcodeItemNumberbuttonGroup3.add(itemNumberRadioButton1);
        itemNumberRadioButton1.setText("item number");

        javax.swing.GroupLayout searchItemPanel3Layout = new javax.swing.GroupLayout(searchItemPanel3);
        searchItemPanel3.setLayout(searchItemPanel3Layout);
        searchItemPanel3Layout.setHorizontalGroup(
            searchItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchItemPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(searchItemTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(searchItemButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(searchItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(barcodeRadioButton1)
                    .addComponent(itemNumberRadioButton1))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        searchItemPanel3Layout.setVerticalGroup(
            searchItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchItemPanel3Layout.createSequentialGroup()
                .addGroup(searchItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchItemPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(searchItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(searchItemTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(searchItemButton1)))
                    .addGroup(searchItemPanel3Layout.createSequentialGroup()
                        .addComponent(barcodeRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(itemNumberRadioButton1)))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        showItemPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Item"));
        showItemPanel3.setToolTipText("");

        ItemTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Name", "Item number", "Location number", "Buying price", "Selling price", "Discount", "Amount in stock", "Barcode", "Supplier", "Description", "Minimum in stock", "Maximum in stock", "Order amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(ItemTable2);

        createItemButton1.setText("Create item");
        createItemButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createItemButton1ActionPerformed(evt);
            }
        });

        updateItemButton1.setText("Update item");
        updateItemButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateItemButton1ActionPerformed(evt);
            }
        });

        deleteItemButton1.setText("Delete item");
        deleteItemButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteItemButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout showItemPanel3Layout = new javax.swing.GroupLayout(showItemPanel3);
        showItemPanel3.setLayout(showItemPanel3Layout);
        showItemPanel3Layout.setHorizontalGroup(
            showItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(showItemPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(showItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 935, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, showItemPanel3Layout.createSequentialGroup()
                        .addComponent(createItemButton1)
                        .addGap(39, 39, 39)
                        .addComponent(updateItemButton1)
                        .addGap(131, 131, 131)
                        .addComponent(deleteItemButton1)))
                .addContainerGap())
        );
        showItemPanel3Layout.setVerticalGroup(
            showItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(showItemPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(showItemPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteItemButton1)
                    .addComponent(updateItemButton1)
                    .addComponent(createItemButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        orderItemButton.setText("Items which have been ordered/have to be ordered ");
        orderItemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderItemButtonActionPerformed(evt);
            }
        });

        updateStockButton.setText("Update stock with new delivery");
        updateStockButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateStockButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabStockItemPanelLayout = new javax.swing.GroupLayout(tabStockItemPanel);
        tabStockItemPanel.setLayout(tabStockItemPanelLayout);
        tabStockItemPanelLayout.setHorizontalGroup(
            tabStockItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabStockItemPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabStockItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabStockItemPanelLayout.createSequentialGroup()
                        .addComponent(searchItemPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 373, Short.MAX_VALUE)
                        .addGroup(tabStockItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(orderItemButton)
                            .addComponent(updateStockButton)))
                    .addComponent(showItemPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        tabStockItemPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {orderItemButton, updateStockButton});

        tabStockItemPanelLayout.setVerticalGroup(
            tabStockItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabStockItemPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabStockItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(searchItemPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(tabStockItemPanelLayout.createSequentialGroup()
                        .addComponent(orderItemButton)
                        .addGap(18, 18, 18)
                        .addComponent(updateStockButton)))
                .addGap(18, 18, 18)
                .addComponent(showItemPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabSupplierPanel.addTab("Stock/Item", tabStockItemPanel);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Type", "Name", "Phone Number", "Address", "City", "ZIPCode", "CVR", "Max Credit"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane4.setViewportView(jTable2);

        jButton2.setText("Create Person");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Edit Person");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Delete Person");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Find Person"));

        findPersonButton.setText("Find");
        findPersonButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findPersonButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("Phone Number:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addComponent(jPhoneTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap(101, Short.MAX_VALUE)
                        .addComponent(findPersonButton)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jPhoneTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addComponent(findPersonButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout tabPersonPanelLayout = new javax.swing.GroupLayout(tabPersonPanel);
        tabPersonPanel.setLayout(tabPersonPanelLayout);
        tabPersonPanelLayout.setHorizontalGroup(
            tabPersonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabPersonPanelLayout.createSequentialGroup()
                .addGroup(tabPersonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabPersonPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(tabPersonPanelLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(tabPersonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(34, 34, 34)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 682, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(401, 401, 401))
        );
        tabPersonPanelLayout.setVerticalGroup(
            tabPersonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tabPersonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabPersonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(tabPersonPanelLayout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE))
                .addGap(131, 131, 131))
        );

        tabSupplierPanel.addTab("Person", tabPersonPanel);

        seachButton1.setText("Search");
        seachButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seachButton1ActionPerformed(evt);
            }
        });

        machineListningjTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Name", "Machine No", "Status", "Price pr. day"
            }
        ));
        jScrollPane2.setViewportView(machineListningjTable1);

        changeStatusButton2.setText("Change Status");
        changeStatusButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeStatusButton2ActionPerformed(evt);
            }
        });

        updateMachineButton3.setText("Update Machine");
        updateMachineButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateMachineButton3ActionPerformed(evt);
            }
        });

        createMachineButton4.setText("Create Machine");
        createMachineButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createMachineButton4ActionPerformed(evt);
            }
        });

        deleteMachineButton5.setText("Delete Machine");
        deleteMachineButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteMachineButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabRentMachinesLayout = new javax.swing.GroupLayout(tabRentMachines);
        tabRentMachines.setLayout(tabRentMachinesLayout);
        tabRentMachinesLayout.setHorizontalGroup(
            tabRentMachinesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabRentMachinesLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(tabRentMachinesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabRentMachinesLayout.createSequentialGroup()
                        .addComponent(machineListTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(seachButton1))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 590, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(55, 55, 55)
                .addGroup(tabRentMachinesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(updateMachineButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(deleteMachineButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                    .addComponent(changeStatusButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                    .addComponent(createMachineButton4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
                .addGap(499, 499, 499))
        );
        tabRentMachinesLayout.setVerticalGroup(
            tabRentMachinesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabRentMachinesLayout.createSequentialGroup()
                .addGap(100, 100, 100)
                .addGroup(tabRentMachinesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(machineListTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(seachButton1))
                .addGap(18, 18, 18)
                .addGroup(tabRentMachinesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabRentMachinesLayout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(tabRentMachinesLayout.createSequentialGroup()
                        .addComponent(changeStatusButton2)
                        .addGap(18, 18, 18)
                        .addComponent(createMachineButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(deleteMachineButton5)
                        .addGap(18, 18, 18)
                        .addComponent(updateMachineButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        tabSupplierPanel.addTab("Rent machines", tabRentMachines);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Find supplier"));

        searchSupplierButton5.setText("Search");
        searchSupplierButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchSupplierButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(searchSupplierTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(searchSupplierButton5)
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(searchSupplierTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(searchSupplierButton5))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        createSupplierButton5.setText("Create supplier");
        createSupplierButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createSupplierButton5ActionPerformed(evt);
            }
        });

        updateSupplierAddressButton5.setText("Update supplier address");

        updateSupplierDeliveryPhoneButton5.setText("Update phone number and delivery time");

        deleteSupplierButton5.setText("Delete supplier");
        deleteSupplierButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteSupplierButton5ActionPerformed(evt);
            }
        });

        supplierTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Supplier name", "Address", "City", "ZIP code", "Phone number", "Delivery time"
            }
        ));
        jScrollPane6.setViewportView(supplierTable3);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(createSupplierButton5)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(updateSupplierAddressButton5)
                    .addComponent(deleteSupplierButton5)
                    .addComponent(updateSupplierDeliveryPhoneButton5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(131, 131, 131))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(createSupplierButton5)
                        .addGap(18, 18, 18)
                        .addComponent(updateSupplierAddressButton5)
                        .addGap(18, 18, 18)
                        .addComponent(updateSupplierDeliveryPhoneButton5)
                        .addGap(18, 18, 18)
                        .addComponent(deleteSupplierButton5)))
                .addContainerGap(131, Short.MAX_VALUE))
        );

        tabSupplierPanel.addTab("Supplier", jPanel3);

        showAllOrdersButton.setText("Show all orders");
        showAllOrdersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showAllOrdersButtonActionPerformed(evt);
            }
        });

        findOrdersTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Date", "Customer name", "Number of items", "Status", "Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane7.setViewportView(findOrdersTable);

        ordersSearchPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Search for specific order"));

        ordersSearchButton.setText("Search");
        ordersSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ordersSearchButtonActionPerformed(evt);
            }
        });

        buttonGroup3.add(ordersIDButton);
        ordersIDButton.setSelected(true);
        ordersIDButton.setText("ID");

        buttonGroup3.add(ordersCustomersNameButton);
        ordersCustomersNameButton.setText("Customers name");

        javax.swing.GroupLayout ordersSearchPanelLayout = new javax.swing.GroupLayout(ordersSearchPanel);
        ordersSearchPanel.setLayout(ordersSearchPanelLayout);
        ordersSearchPanelLayout.setHorizontalGroup(
            ordersSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ordersSearchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ordersSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(ordersSearchPanelLayout.createSequentialGroup()
                        .addComponent(ordersSearchTextfield, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ordersSearchButton))
                    .addGroup(ordersSearchPanelLayout.createSequentialGroup()
                        .addComponent(ordersIDButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(ordersCustomersNameButton)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        ordersSearchPanelLayout.setVerticalGroup(
            ordersSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ordersSearchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ordersSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ordersIDButton)
                    .addComponent(ordersCustomersNameButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addGroup(ordersSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ordersSearchTextfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ordersSearchButton))
                .addContainerGap())
        );

        ordersDeleteButton.setText("Delete order");
        ordersDeleteButton.setToolTipText("Select the order you want to delete in the table");
        ordersDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ordersDeleteButtonActionPerformed(evt);
            }
        });

        ordersClearTableButton.setText("Clear Table");
        ordersClearTableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ordersClearTableButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabOrdersLayout = new javax.swing.GroupLayout(tabOrders);
        tabOrders.setLayout(tabOrdersLayout);
        tabOrdersLayout.setHorizontalGroup(
            tabOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrdersLayout.createSequentialGroup()
                .addGroup(tabOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabOrdersLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(ordersSearchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(tabOrdersLayout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addGroup(tabOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(showAllOrdersButton)
                            .addComponent(ordersDeleteButton)))
                    .addGroup(tabOrdersLayout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(ordersClearTableButton)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 723, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabOrdersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {ordersDeleteButton, showAllOrdersButton});

        tabOrdersLayout.setVerticalGroup(
            tabOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabOrdersLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
                    .addGroup(tabOrdersLayout.createSequentialGroup()
                        .addComponent(ordersSearchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ordersDeleteButton)
                        .addGap(18, 18, 18)
                        .addComponent(showAllOrdersButton)
                        .addGap(18, 18, 18)
                        .addComponent(ordersClearTableButton)))
                .addContainerGap())
        );

        tabSupplierPanel.addTab("Orders", tabOrders);

        javax.swing.GroupLayout mainMenuPanelLayout = new javax.swing.GroupLayout(mainMenuPanel);
        mainMenuPanel.setLayout(mainMenuPanelLayout);
        mainMenuPanelLayout.setHorizontalGroup(
            mainMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainMenuPanelLayout.createSequentialGroup()
                .addComponent(tabSupplierPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 992, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );
        mainMenuPanelLayout.setVerticalGroup(
            mainMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabSupplierPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(979, Short.MAX_VALUE)
                        .addComponent(logOutButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(891, 891, 891)
                        .addComponent(loggedInAsLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(mainMenuPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(loggedInAsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(logOutButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainMenuPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void checkLogin()
    {
        if(!loginName.equals("manager"))
        {
            deleteItemButton1.setEnabled(false);
            createItemButton1.setEnabled(false);
        }
                 
    }
    
    private void updateAmountInStock(int idOnOrder)
    {
        int orderIndex = idOnOrder-1;
        int index = 0;
        while(index < orderController.listAllOrder().get(orderIndex).getPartOrders().size())
        {
            int amountSold = orderController.listAllOrder().get(orderIndex).getPartOrders().get(index).getAmount();
            int amountInStock = orderController.listAllOrder().get(orderIndex).getPartOrders().get(index).getItem().getAmountInStock();
            orderController.listAllOrder().get(orderIndex).getPartOrders().get(index).getItem().setAmountInStock(amountInStock-amountSold);
            index++;
        }
    }
    
    
    private void clearSaleLabels()
    {
        saleCustomersNameLabel.setText("Customers name: ");
        saleDateLabel.setText("Date: ");
        saleOrderIDLabel.setText("Order ID: ");
        saleStatusLabel.setText("");
        saleStatusOnOrderLabel.setText("Status on order: ");
        saleTotalPriceLabel.setText("Total price: ");
        saleTotalPriceNoVATLabel.setText("Total price no VAT: ");
        saleVATLabel.setText("VAT: ");
    }
    
    private void saleCreateAndCancelButtonsFalse()
    {
        salePayButton.setEnabled(false);
        saleCancelOrderButton.setEnabled(false);
    }
    
    private void saleCreateAndCancelButtonsTrue()
    {
        salePayButton.setEnabled(true);
        saleCancelOrderButton.setEnabled(true);
    }
    
    private double calculateTotalPrice()
    {
        int rowCount = 0;
        double totalPrice = 0;
        
        while(rowCount < orderTabel.getRowCount() && orderTabel.getValueAt(rowCount, 6) != null)
        {
            totalPrice += (Double) orderTabel.getValueAt(rowCount, 6);
            rowCount++;
        }
        return totalPrice;
    }
    
    private double calculateTotalPriceNoVAT()
    {
        double totalPrice = calculateTotalPrice();
        return totalPrice - (totalPrice* orderController.listAllOrder().get(orderID-1).getVAT());
    }
    
    private void setAllPriceLabels()
    {
        totalPriceLabel.setText("Total price: " + calculateTotalPrice());
        totalPriceNoVATLabel.setText("Total price no VAT: " + calculateTotalPriceNoVAT());
        VATLabel.setText("VAT: " + (calculateTotalPrice() - calculateTotalPriceNoVAT()));
    }
    
    private void setDate()
    {
        dateLabel.setText("Date: " + orderController.timeAndDate());
    }
    private void setOrderID()
    {
        orderIDLabel.setText("Order ID: " + orderController.getLastCreatedOrderId());
    }    
    private void OrderAndFindItemAndDeleteAndCancelButtonsFalse()
    {
        createOrderButton.setEnabled(false);
        searchButton.setEnabled(false);
        deleteItemButton.setEnabled(false);
        cancelOrderButton.setEnabled(false);
        searchField.setEnabled(false);
    }
    private void OrderAndFindItemAndDeleteAndCancelButtonsTrue()
    {
        createOrderButton.setEnabled(true);
        searchButton.setEnabled(true);
        deleteItemButton.setEnabled(true);
        cancelOrderButton.setEnabled(true);
        searchField.setEnabled(true);
    }
    private void resetItemDetails()
    {
        nameLabel.setText("Name:");
        barcodeLabel.setText("Barcode:");
        itemLabel.setText("Item nb:");
        locationLabel.setText("Location:");
        inStockLabel.setText("In stock:");
        priceLabel.setText("Price:");
        discountLabel.setText("Discount:");       
    }
    
    
    private void logOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logOutButtonActionPerformed
        
        if(setOrderNameCreated == true)
        {
            try
            {
                orderController.deleteOrder(orderID);
                this.dispose();
                loginGUI.setVisible(true);   
            }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
        }
        else
            {
                this.dispose();
                loginGUI.setVisible(true);
            }
    }//GEN-LAST:event_logOutButtonActionPerformed

    private void searchFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchFieldActionPerformed

    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
        if(orderTabel.getValueAt(orderTabel.getRowCount()-1, 0) != null)
        {
            controllingFrame = this;
            JOptionPane.showMessageDialog(controllingFrame, "You cant add more items to this order"," No more space on this order", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            if(barcodeButton.isSelected())
            {
                if(orderController.findItemByBarcode(searchField.getText()) != null)
                {   
                    int index = 0;
                    boolean found = false;
                    while(index < orderTabel.getRowCount() && !found)
                    {   
                        if(orderController.findItemByBarcode(searchField.getText()).getBarcode().equals(orderTabel.getValueAt(index, 1)))
                            
                                {
                                    found = true;
                                }
                        else
                        {
                            index++;
                        }
                        System.out.println(found);
                    }
                    if(!found)
                    {
                    
                        String name = orderController.findItemByBarcode(searchField.getText()).getName();
                        String barcode = orderController.findItemByBarcode(searchField.getText()).getBarcode();
                        String itemNumber = orderController.findItemByBarcode(searchField.getText()).getItemNumber();
                        String location = orderController.findItemByBarcode(searchField.getText()).getLocationsNumber();
                        int amountInStock = orderController.findItemByBarcode(searchField.getText()).getAmountInStock();
                        double price = orderController.findItemByBarcode(searchField.getText()).getSellingPrice();
                        int discount = orderController.findItemByBarcode(searchField.getText()).getDiscount();

                        nameLabel.setText("Name: " + name);
                        barcodeLabel.setText("Barcode: " + barcode);
                        itemLabel.setText("Item nb: " + itemNumber);
                        locationLabel.setText("Location: " + location);
                        inStockLabel.setText("In stock: " + amountInStock);
                        priceLabel.setText("Price: " + price);
                        discountLabel.setText("Discount: " + discount);

                        int amount = 1;
                        int column = 0;
                        double totalPrice = 0;

                        orderTabel.setValueAt(name, row, column);
                        column++;
                        orderTabel.setValueAt(barcode, row, column);
                        column++;
                        orderTabel.setValueAt(itemNumber, row, column);
                        column++;
                        orderTabel.setValueAt(location, row, column);
                        column++;
                        orderTabel.setValueAt(amount, row, column);
                        column++;
                        orderTabel.setValueAt(price, row, column);
                        column++;
                        totalPrice = price * amount;
                        orderTabel.setValueAt(totalPrice, row, column);
                        row++;
                    }
                    else
                    {
                        if((Integer) orderTabel.getValueAt(index, 4) < orderController.findItemByBarcode(searchField.getText()).getAmountInStock())
                        {
                           orderTabel.setValueAt((Integer) orderTabel.getValueAt(index, 4)+1, index, 4);
                           int amount = (Integer) orderTabel.getValueAt(index, 4);
                           orderTabel.setValueAt((Double) orderTabel.getValueAt(index, 5)*amount, index, 6);
                        }
                        else
                        {
                            JOptionPane.showMessageDialog(this, "Amount not in stock!\nAmount in stock: " + orderController.findItemByBarcode((String)orderTabel.getValueAt(index, 1)).getAmountInStock(),"STOCK Warning", JOptionPane.WARNING_MESSAGE);
                        }
                        
                    }
                }
                else
                {
                    System.out.println("Item not found");
                    controllingFrame = this;
                    JOptionPane.showMessageDialog(controllingFrame, "No item is found by this barcode"," No result", JOptionPane.WARNING_MESSAGE);
                }
            }
            else
            {
                if(orderController.findItemByItemNumber(searchField.getText()) != null)
                {
                    int index = 0;
                    boolean found = false;
                    while(index < orderTabel.getRowCount() && !found)
                    {   
                        if(orderController.findItemByItemNumber(searchField.getText()).getItemNumber().equals(orderTabel.getValueAt(index, 2)))
                            
                                {
                                    found = true;
                                }
                        else
                        {
                            index++;
                        }
                        System.out.println(found);
                    }
                    if(!found)
                    {
                        String name = orderController.findItemByItemNumber(searchField.getText()).getName();
                        String barcode = orderController.findItemByItemNumber(searchField.getText()).getBarcode();
                        String itemNumber = orderController.findItemByItemNumber(searchField.getText()).getItemNumber();
                        String location = orderController.findItemByItemNumber(searchField.getText()).getLocationsNumber();
                        int amountInStock = orderController.findItemByItemNumber(searchField.getText()).getAmountInStock();
                        double price = orderController.findItemByItemNumber(searchField.getText()).getSellingPrice();
                        int discount = orderController.findItemByItemNumber(searchField.getText()).getDiscount();

                        nameLabel.setText("Name: " + name);
                        barcodeLabel.setText("Barcode: " + barcode);
                        itemLabel.setText("Item nb: " + itemNumber);
                        locationLabel.setText("Location: " + location);
                        inStockLabel.setText("In stock: " + amountInStock);
                        priceLabel.setText("Price: " + price);
                        discountLabel.setText("Discount: " + discount);

                        int amount = 1;
                        int column = 0;
                        double totalPrice = 0;

                        orderTabel.setValueAt(name, row, column);
                        column++;
                        orderTabel.setValueAt(barcode, row, column);
                        column++;
                        orderTabel.setValueAt(itemNumber, row, column);
                        column++;
                        orderTabel.setValueAt(location, row, column);
                        column++;
                        orderTabel.setValueAt(amount, row, column);
                        column++;
                        orderTabel.setValueAt(price, row, column);
                        column++;
                        totalPrice = price * amount;
                        orderTabel.setValueAt(totalPrice, row, column);
                        row++;
                    }
                    else
                    {
                        if((Integer) orderTabel.getValueAt(index, 4) < orderController.findItemByItemNumber(searchField.getText()).getAmountInStock())
                        {
                           orderTabel.setValueAt((Integer) orderTabel.getValueAt(index, 4)+1, index, 4);
                           int amount = (Integer) orderTabel.getValueAt(index, 4);
                           orderTabel.setValueAt((Double) orderTabel.getValueAt(index, 5)*amount, index, 6);
                        }
                        else
                        {
                            JOptionPane.showMessageDialog(this, "Amount not in stock!\nAmount in stock: " + orderController.findItemByBarcode((String)orderTabel.getValueAt(index, 1)).getAmountInStock(),"STOCK Warning", JOptionPane.WARNING_MESSAGE);
                        }
                    }
                }
                else
                {
                    System.out.println("Item not found");
                    controllingFrame = this;
                    JOptionPane.showMessageDialog(controllingFrame, "No item is found by this item number"," No result", JOptionPane.WARNING_MESSAGE);
                }
            }
        setAllPriceLabels();                
        }
    }//GEN-LAST:event_searchButtonActionPerformed

    private void customersNameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customersNameButtonActionPerformed
        orderController.createOrder(customersName1Field.getText());
        customersNameButton.setEnabled(false);
        customersName1Field.setEnabled(false);
        OrderAndFindItemAndDeleteAndCancelButtonsTrue();
        setDate();
        setOrderID();
        setOrderNameCreated = true;
       
        totalPriceLabel.setText("Total price:");
        totalPriceNoVATLabel.setText("Total price no VAT");
        VATLabel.setText("VAT:");
                
        orderID = orderController.getLastCreatedOrderId();
        customersName1Label.setText("Customers Name: " + customersName1Field.getText());
        orderSentLabel.setText("");
        orderSentLabel.setBackground(null);
}//GEN-LAST:event_customersNameButtonActionPerformed

    private void cancelOrderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelOrderButtonActionPerformed
        try
        {
            orderController.deleteOrder(orderID);
            OrderAndFindItemAndDeleteAndCancelButtonsFalse();
            customersNameButton.setEnabled(true);
            customersName1Field.setEnabled(true);
            customersName1Field.setText("");
            resetItemDetails();
            barcodeButton.doClick();
            row = 0;
            clearTable(orderTabel);
            
            setOrderNameCreated = false;
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }//GEN-LAST:event_cancelOrderButtonActionPerformed

    private void createOrderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createOrderButtonActionPerformed
        if(orderTabel.getValueAt(0, 0) == null)
        {
            System.out.println("You have no items");
            controllingFrame = this;
            JOptionPane.showMessageDialog(controllingFrame, "NO item(s) is added to the order"," Add items", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            int orderIndex = orderID - 1;
            int rows = 0;
            int partOrderIndex = 0;
            while(rows < orderTabel.getRowCount() && orderTabel.getValueAt(rows, 4) != null)
            {
                int amount = (Integer) orderTabel.getValueAt(rows, 4);
                String barcode = (String) orderTabel.getValueAt(rows, 1);
                
                orderController.createPartOrderAndAddToOrder(amount, barcode);
                
                if(orderController.listAllOrder().get(orderIndex).getPartOrders().get(partOrderIndex).getPartOrderPrice() != orderTabel.getValueAt(rows, 5))
                {
                    double newPriceTotal = (Double) orderTabel.getValueAt(rows, 6);
                    orderController.listAllOrder().get(orderIndex).getPartOrders().get(partOrderIndex).setPartOrderPrice(newPriceTotal);
                    
                    double VAT = newPriceTotal* orderController.listAllOrder().get(orderIndex).getVAT();
                    
                    orderController.listAllOrder().get(orderIndex).getPartOrders().get(partOrderIndex).setPartOrderPriceNoVAT(newPriceTotal-VAT);
                    
                }
                partOrderIndex++;
                rows++;
            }
                   
            System.out.println("Sent to stockworker");
            orderController.listAllOrder().get(orderIndex).setStatus("stock");
            orderController.listAllOrder().get(orderIndex).setDate(orderController.timeAndDate());                
            orderController.calculateOrderPrice();
            
            OrderAndFindItemAndDeleteAndCancelButtonsFalse();
            customersNameButton.setEnabled(true);
            customersName1Field.setEnabled(true);
            customersName1Field.setText("");
            resetItemDetails();
            barcodeButton.doClick();
            row = 0;
            clearTable(orderTabel);
            
            orderSentLabel.setText("Sent to stock");
            orderSentLabel.setBackground(Color.green);
            setOrderNameCreated = false;
        }
        
        
    }//GEN-LAST:event_createOrderButtonActionPerformed
  
    private void clearTable(JTable table)
{
    int rowCount = 0;
    while(rowCount < table.getRowCount())
    {
        clearColumn(table, rowCount);
        rowCount++;
    }
}   
    
    private void clearColumn(JTable table, int row)
{
    int column = 0;
    int size = table.getColumnCount();
    while(column < size)
    {
        table.setValueAt(null, row, column);
        column++;
    }
} 
    private void barcodeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_barcodeButtonActionPerformed
        
    }//GEN-LAST:event_barcodeButtonActionPerformed

    private void itemNumberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemNumberButtonActionPerformed
       
    }//GEN-LAST:event_itemNumberButtonActionPerformed

    private void updateMachineButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateMachineButton3ActionPerformed
        if(machineListningjTable1.getSelectedColumnCount() == 0){
            JOptionPane.showMessageDialog(controllingFrame, "No machine has been selected","Not found", JOptionPane.WARNING_MESSAGE);
        }else{

        Integer getCell = (Integer)machineListningjTable1.getValueAt(machineListningjTable1.getSelectedRow(), 1);

        try{


        if(rentalCon.findMachine(getCell) != null){

            UpdateMachine updateMachineGUI = new UpdateMachine(rentalCon.findMachine(getCell));
            updateMachineGUI.setVisible(true);
            clearJTable2();
        }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(controllingFrame, "Not found","Not found", JOptionPane.WARNING_MESSAGE);

    }
    }
    }//GEN-LAST:event_updateMachineButton3ActionPerformed

    private void changeStatusButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeStatusButton2ActionPerformed
        Integer newString = (Integer)machineListningjTable1.getValueAt(machineListningjTable1.getSelectedRow(), 1);
        try{
        if(rentalCon.getStatus(newString) == true)
        {
            rentalCon.machineDelivered(newString);
        }
        else
        {rentalCon.rentMachine(newString);}
        }
        catch(Exception e)
            {
                System.out.println(e.getMessage());
                controllingFrame = this;
                JOptionPane.showMessageDialog(controllingFrame, "Status has not been changed!","Machine Status", JOptionPane.INFORMATION_MESSAGE);
            }   
    }//GEN-LAST:event_changeStatusButton2ActionPerformed

    private void createMachineButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createMachineButton4ActionPerformed
        CreateMachine createMachineGUI = new CreateMachine();
        createMachineGUI.setBounds((loginGUI.getWidthStartWindow()+(1050/2)-(400/2)), loginGUI.getHeightStartWindow()+(600/2)-(250/2), 400,250);
        createMachineGUI.setVisible(true);
    }//GEN-LAST:event_createMachineButton4ActionPerformed

    private void deleteMachineButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMachineButton5ActionPerformed
        try {
            Integer newString = (Integer)machineListningjTable1.getValueAt(machineListningjTable1.getSelectedRow(), 1);
            rentalCon.removeMachine(newString);
          
          int rowsInTable = machineListningjTable1.getRowCount();
        int selectedRow = machineListningjTable1.getSelectedRow();
        int rowToMoveUp = selectedRow +1;
        if(machineListningjTable1.getSelectedRow() == -1)
        {
            controllingFrame = this;
            JOptionPane.showMessageDialog(controllingFrame, "No item is selected","Not selected", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            if(machineListningjTable1.getValueAt(selectedRow, 0) != null)
            {
                if(selectedRow == rowsInTable-1)
                {
                    machineListningjTable1.setValueAt(null, selectedRow , 0);
                    machineListningjTable1.setValueAt(null, selectedRow , 1);
                    machineListningjTable1.setValueAt(null, selectedRow , 2);
                    machineListningjTable1.setValueAt(null, selectedRow , 3);
                }
                else
                {
                    while(rowToMoveUp <= rowsInTable-1)
                    {

                        machineListningjTable1.setValueAt(machineListningjTable1.getValueAt(rowToMoveUp, 0), selectedRow, 0);            
                        machineListningjTable1.setValueAt(machineListningjTable1.getValueAt(rowToMoveUp, 1), selectedRow, 1);
                        machineListningjTable1.setValueAt(machineListningjTable1.getValueAt(rowToMoveUp, 2), selectedRow, 2);
                        machineListningjTable1.setValueAt(machineListningjTable1.getValueAt(rowToMoveUp, 3), selectedRow, 3);
                        rowToMoveUp++;
                        selectedRow++;
                    }
                }
            }
        }
        } catch (Exception e) {
          System.out.println(e.getMessage());
          controllingFrame = this;
          JOptionPane.showMessageDialog(controllingFrame, "Selected row is empty. Cant be deleted","Empty row", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_deleteMachineButton5ActionPerformed

    private void deleteItemMakeOrder()
    {
        int rowsInTable = orderTabel.getRowCount();
        int selectedRow = orderTabel.getSelectedRow();
        int rowToMoveUp = selectedRow +1;
        if(orderTabel.getSelectedRow() == -1)
        {
            controllingFrame = this;
            JOptionPane.showMessageDialog(controllingFrame, "No item is selected","Not selected", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            if(orderTabel.getValueAt(selectedRow, 0) != null)
            {
                if(selectedRow == rowsInTable-1)
                {
                    orderTabel.setValueAt(null, selectedRow , 0);
                    orderTabel.setValueAt(null, selectedRow , 1);
                    orderTabel.setValueAt(null, selectedRow , 2);
                    orderTabel.setValueAt(null, selectedRow , 3);
                    orderTabel.setValueAt(null, selectedRow , 4);
                    orderTabel.setValueAt(null, selectedRow , 5);
                    orderTabel.setValueAt(null, selectedRow , 6);

                }
                else
                {


                    while(rowToMoveUp <= rowsInTable-1)
                    {

                        orderTabel.setValueAt(orderTabel.getValueAt(rowToMoveUp, 0), selectedRow, 0);            
                        orderTabel.setValueAt(orderTabel.getValueAt(rowToMoveUp, 1), selectedRow, 1);
                        orderTabel.setValueAt(orderTabel.getValueAt(rowToMoveUp, 2), selectedRow, 2);
                        orderTabel.setValueAt(orderTabel.getValueAt(rowToMoveUp, 3), selectedRow, 3);
                        orderTabel.setValueAt(orderTabel.getValueAt(rowToMoveUp, 4), selectedRow, 4);
                        orderTabel.setValueAt(orderTabel.getValueAt(rowToMoveUp, 5), selectedRow, 5);
                        orderTabel.setValueAt(orderTabel.getValueAt(rowToMoveUp, 6), selectedRow, 6);
                        rowToMoveUp++;
                        selectedRow++;
                    }
                }
                row--;
                setAllPriceLabels();
            }
            else
            {
                controllingFrame = this;
                JOptionPane.showMessageDialog(controllingFrame, "Selected row is empty. Cant be deleted","Empty row", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }
    
    private void deleteItemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteItemButtonActionPerformed
        deleteItemMakeOrder();
    }//GEN-LAST:event_deleteItemButtonActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        CreatePerson createPersonGUI = new CreatePerson();
        createPersonGUI.setVisible(true);
}//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed


 if(jTable2.getSelectedColumnCount() == 0){

        }else{
        Integer getCell = (Integer)jTable2.getValueAt(jTable2.getSelectedRow(), 2);

        try{


        if(personController.findPerson(getCell) != null){

            personController.deletePerson(getCell);
            JOptionPane.showMessageDialog(controllingFrame, "Person has been removed from system...","Deleted", JOptionPane.WARNING_MESSAGE);
            clearJTable2();



        }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(controllingFrame, "Person not found","Not found", JOptionPane.WARNING_MESSAGE);
        }

        }

}//GEN-LAST:event_jButton4ActionPerformed
    
    private void findPersonButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findPersonButtonActionPerformed

        clearJTable2();
        try{
            // the first part of the code typecasts the Person object, without this, the instance variables from the different class-roles, are unavailable
            //        jTable2.
            Person newPerson = personController.findPerson(Integer.parseInt(jPhoneTxt.getText()));
            int rows = 0;
            int columns = 0;
            if(newPerson != null) {
                if(newPerson instanceof PrivateCustomer) {
                    PrivateCustomer newObj = (PrivateCustomer) newPerson;
                    jTable2.setValueAt(newObj.getRoleName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getPhoneNumber(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getAddress(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getCity(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getZIPCode(), rows, columns);
                    columns++;
                    jTable2.setValueAt("null", rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getMaxCredit(), rows, columns);
                    columns++;
                } else if(newPerson instanceof BusinessCustomer) {
                    BusinessCustomer newObj = (BusinessCustomer) newPerson;
                    jTable2.setValueAt(newObj.getRoleName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getPhoneNumber(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getAddress(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getCity(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getZIPCode(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getCVR(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getMaxCredit(), rows, columns);
                    columns++;
                } else if(newPerson instanceof Salesman) {
                    Salesman newObj = (Salesman) newPerson;
                    jTable2.setValueAt(newObj.getRoleName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getPhoneNumber(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getAddress(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getCity(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getZIPCode(), rows, columns);
                    columns++;
                    jTable2.setValueAt("null", rows, columns);
                    columns++;
                    jTable2.setValueAt("null", rows, columns);
                    columns++;

                } else if(newPerson instanceof Manager) {
                    Manager newObj = (Manager) newPerson;
                    jTable2.setValueAt(newObj.getRoleName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getPhoneNumber(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getAddress(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getCity(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getZIPCode(), rows, columns);
                    columns++;
                    jTable2.setValueAt("null", rows, columns);
                    columns++;
                    jTable2.setValueAt("null", rows, columns);
                    columns++;
                } else if(newPerson instanceof WarehouseEmployee) {
                    WarehouseEmployee newObj = (WarehouseEmployee) newPerson;
                    jTable2.setValueAt(newObj.getRoleName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getName(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getPhoneNumber(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getAddress(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getCity(), rows, columns);
                    columns++;
                    jTable2.setValueAt(newObj.getZIPCode(), rows, columns);
                    columns++;
                    jTable2.setValueAt("null", rows, columns);
                    columns++;
                    jTable2.setValueAt("null", rows, columns);
                    columns++;
                }
                rows++;
            }
            jTable2.repaint();

        }catch(Exception e){
             JOptionPane.showMessageDialog(controllingFrame, "Person was not found...","Error", JOptionPane.ERROR_MESSAGE);
             jTable2.repaint();
        }
    }//GEN-LAST:event_findPersonButtonActionPerformed

    private void createItemButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createItemButton1ActionPerformed
        CreateItem createItem = new CreateItem();
        createItem.setBounds((loginGUI.getWidthStartWindow()+(1050/2)-(400/2)), loginGUI.getHeightStartWindow()+(600/2)-(250/2), 450,700);
        createItem.setVisible(true);
    }//GEN-LAST:event_createItemButton1ActionPerformed

    private void UnregistredButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UnregistredButtonActionPerformed
        jPanel7.setVisible(false);    }//GEN-LAST:event_UnregistredButtonActionPerformed

    private void saleOKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saleOKButtonActionPerformed

            
            try
            {
                int idOnOrder = Integer.parseInt(idField.getText());
                if(orderController.findOrder(idOnOrder).getStatus().equals("canceled") || orderController.findOrder(idOnOrder).getStatus().equals("delivered"))
                {
                    JOptionPane.showMessageDialog(this, "This order is canceled or paid","Order cant be paid", JOptionPane.INFORMATION_MESSAGE);
                    saleCreateAndCancelButtonsFalse();
                }
                else
                {
                saleDateLabel.setText("Date: " + orderController.findOrder(idOnOrder).getDate());
                saleTotalPriceLabel.setText("Total price: " + orderController.findOrder(idOnOrder).getTotalPrice());
                saleVATLabel.setText("VAT: " + orderController.findOrder(idOnOrder).getVATPrice());
                saleTotalPriceNoVATLabel.setText("Total price No VAT: " + orderController.findOrder(idOnOrder).getWithoutVAT());
                saleCustomersNameLabel.setText("Customers name: " + orderController.findOrder(idOnOrder).getCustomersName());
                saleStatusLabel.setText(orderController.findOrder(idOnOrder).getStatus());
                saleOrderIDLabel.setText("Order ID: " + orderController.findOrder(idOnOrder).getId());
                saleCreateAndCancelButtonsTrue();
                int rows = 0;
                int index = 0;
                while(index < orderController.findOrder(idOnOrder).getPartOrders().size())
                {
                    String name = orderController.findOrder(idOnOrder).getPartOrders().get(index).getItem().getName();
                    String barcode = orderController.findOrder(idOnOrder).getPartOrders().get(index).getItem().getBarcode();
                    String itemNb = orderController.findOrder(idOnOrder).getPartOrders().get(index).getItem().getItemNumber();
                    String location = orderController.findOrder(idOnOrder).getPartOrders().get(index).getItem().getLocationsNumber();
                    int amountOrdered = orderController.findOrder(idOnOrder).getPartOrders().get(index).getAmount();
                    double totalPrice = orderController.findOrder(idOnOrder).getPartOrders().get(index).getPartOrderPrice();
                    double discountOnPartOrder = (orderController.findOrder(idOnOrder).getPartOrders().get(index).getItem().getSellingPrice() * amountOrdered) - totalPrice;

                    saleOrderTabel.setValueAt(name, rows, 0);
                    saleOrderTabel.setValueAt(barcode, rows, 1);
                    saleOrderTabel.setValueAt(itemNb, rows, 2);
                    saleOrderTabel.setValueAt(location, rows, 3);
                    saleOrderTabel.setValueAt(amountOrdered, rows, 4);
                    saleOrderTabel.setValueAt(-discountOnPartOrder, rows, 5);
                    saleOrderTabel.setValueAt(totalPrice, rows, 6);
                    rows++;
                    index++;
                }
                }          
                
            }
            catch(Exception e)
            {
                e.getMessage();
                JOptionPane.showMessageDialog(this, "No order is found with that ID","No order found", JOptionPane.INFORMATION_MESSAGE);
            }
            
        
    }//GEN-LAST:event_saleOKButtonActionPerformed

    private void saleCancelOrderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saleCancelOrderButtonActionPerformed
        saleCreateAndCancelButtonsFalse();
        int idOnOrder = Integer.parseInt(idField.getText());
        try
        {
            clearSaleLabels();
            clearTable(saleOrderTabel);
            orderController.findOrder(idOnOrder).setStatus("canceled");       
        }
        catch(Exception e)
        {
            e.getMessage();
        }

    }//GEN-LAST:event_saleCancelOrderButtonActionPerformed

    private void salePayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salePayButtonActionPerformed
        try
        {
            saleCreateAndCancelButtonsFalse();
            int idOnOrder = Integer.parseInt(idField.getText());
            clearSaleLabels();
            if(orderController.findOrder(idOnOrder) != null)
            {
                clearTable(saleOrderTabel);
                if(orderController.findOrder(idOnOrder).getStatus().equals("canceled"))
                {
                    controllingFrame = this;
                    JOptionPane.showMessageDialog(controllingFrame, "This order is canceled. Cant be paid","Order cant be paid", JOptionPane.ERROR_MESSAGE);
                }
                else
                {
                    controllingFrame = this;
                    JOptionPane.showMessageDialog(controllingFrame, "Success! Paid!");
                    orderController.findOrder(idOnOrder).setStatus("delivered");
                    updateAmountInStock(idOnOrder);
                }
            }
            

        }
        catch(Exception e)
        {
            e.getMessage();
        }

    }//GEN-LAST:event_salePayButtonActionPerformed

    private void createSupplierButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createSupplierButton5ActionPerformed
        CreateSupplier createSupplier = new CreateSupplier();
        createSupplier.setBounds((loginGUI.getWidthStartWindow()+(1050/2)-(400/2)), loginGUI.getHeightStartWindow()+(600/2)-(250/2), 400,500);
        createSupplier.setVisible(true);
    }//GEN-LAST:event_createSupplierButton5ActionPerformed

    private void orderTabelComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_orderTabelComponentAdded
        orderTabelChanged();
    }//GEN-LAST:event_orderTabelComponentAdded

    private void orderTabelComponentRemoved(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_orderTabelComponentRemoved
        orderTabelChanged();
    }//GEN-LAST:event_orderTabelComponentRemoved
    private void orderTabelChanged()
    {
         int mouseEnteredRow = orderTabel.getSelectedRow();
        
         try
        {
        if((Integer) orderTabel.getValueAt(mouseEnteredRow, 4) == 0)
        {
            deleteItemMakeOrder();
            int amount = (Integer) orderTabel.getValueAt(mouseEnteredRow, 4);
            double priceStc = (Double) orderTabel.getValueAt(mouseEnteredRow,5);
            orderTabel.setValueAt(amount*priceStc, mouseEnteredRow, 6);
            setAllPriceLabels();
        }
        
        else if((Integer) orderTabel.getValueAt(mouseEnteredRow, 4) > itemController.findItemByBarcode((String)orderTabel.getValueAt(mouseEnteredRow, 1)).getAmountInStock())
                {
                    JOptionPane.showMessageDialog(this, "Amount not in stock!\nAmount in stock: " + itemController.findItemByBarcode((String)orderTabel.getValueAt(mouseEnteredRow, 1)).getAmountInStock(),"STOCK Warning", JOptionPane.WARNING_MESSAGE);
                    orderTabel.setValueAt(1, mouseEnteredRow, 4);
                    orderTabel.setValueAt(orderTabel.getValueAt(mouseEnteredRow, 5), mouseEnteredRow, 6);
                    setAllPriceLabels();
                }
        else
        {
            int amount = (Integer) orderTabel.getValueAt(mouseEnteredRow, 4);
            double priceStc = (Double) orderTabel.getValueAt(mouseEnteredRow,5);
            orderTabel.setValueAt(amount*priceStc, mouseEnteredRow, 6);
            setAllPriceLabels();
        }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
    private void searchSupplierButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchSupplierButton5ActionPerformed
        try {
           
            //if(supplierController.findSupplier(searchSupplierTextField3.getText()) !=null)
                if(supplierController.findSupplier(searchSupplierTextField3.getText()).getName().equals(searchSupplierTextField3.getText()))
                {
                    String name = supplierController.findSupplier(searchSupplierTextField3.getText()).getName();
                    String address = supplierController.findSupplier(searchSupplierTextField3.getText()).getAddress();
                    String city = supplierController.findSupplier(searchSupplierTextField3.getText()).getCity();
                    int ZIPCode = supplierController.findSupplier(searchSupplierTextField3.getText()).getZIPCode();
                    int phoneNumber = supplierController.findSupplier(searchSupplierTextField3.getText()).getPhoneNumber();
                    String deliveryTime = supplierController.findSupplier(searchSupplierTextField3.getText()).getDeliveryTime();
               
                    supplierTable3.setValueAt(name, 0, 0);
                    supplierTable3.setValueAt(address, 0, 1);
                    supplierTable3.setValueAt(city, 0, 2);
                    supplierTable3.setValueAt(ZIPCode, 0, 3);
                    supplierTable3.setValueAt(phoneNumber, 0, 4);
                    supplierTable3.setValueAt(deliveryTime, 0, 5);
                }

                 } catch (Exception e) {
                    System.out.println(e.getMessage());
                    controllingFrame = this;
                    JOptionPane.showMessageDialog(controllingFrame, "The supplier was not found","Warning",JOptionPane.INFORMATION_MESSAGE);  
                 }
    }//GEN-LAST:event_searchSupplierButton5ActionPerformed

    public void clearJTable2(){
        int rowCount = 0;
        while(rowCount < 20)
        {
            jTable2.setValueAt(null, rowCount, 0);
                jTable2.setValueAt(null, rowCount, 1);
                jTable2.setValueAt(null, rowCount, 2);
                jTable2.setValueAt(null, rowCount, 3);
                jTable2.setValueAt(null, rowCount, 4);
                jTable2.setValueAt(null, rowCount, 5);
                jTable2.setValueAt(null, rowCount, 6);
                jTable2.setValueAt(null, rowCount, 7);
                rowCount++;
            }
        }
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed


        if(jTable2.getSelectedColumnCount() == 0){
            JOptionPane.showMessageDialog(controllingFrame, "No person selected","Not found", JOptionPane.WARNING_MESSAGE);
        }else{

        Integer getCell = (Integer)jTable2.getValueAt(jTable2.getSelectedRow(), 2);

        try{


        if(personController.findPerson(getCell) != null){

            EditPerson editPersonGUI = new EditPerson(personController.findPerson(getCell));
            editPersonGUI.setVisible(true);
            clearJTable2();
        }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(controllingFrame, "Not found","Not found", JOptionPane.WARNING_MESSAGE);

    }
    }

    }//GEN-LAST:event_jButton3ActionPerformed

    private void deleteSupplierButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteSupplierButton5ActionPerformed
        try {
            String newString = (String)supplierTable3.getValueAt(supplierTable3.getSelectedRow(), 0);
          supplierController.deleteSupplier(newString);
          
          int rowsInTable = supplierTable3.getRowCount();
        int selectedRow = supplierTable3.getSelectedRow();
        int rowToMoveUp = selectedRow +1;
        if(supplierTable3.getSelectedRow() == -1)
        {
            controllingFrame = this;
            JOptionPane.showMessageDialog(controllingFrame, "No item is selected","Not selected", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            if(supplierTable3.getValueAt(selectedRow, 0) != null)
            {
                if(selectedRow == rowsInTable-1)
                {
                    supplierTable3.setValueAt(null, selectedRow , 0);
                    supplierTable3.setValueAt(null, selectedRow , 1);
                    supplierTable3.setValueAt(null, selectedRow , 2);
                    supplierTable3.setValueAt(null, selectedRow , 3);
                    supplierTable3.setValueAt(null, selectedRow , 4);
                    supplierTable3.setValueAt(null, selectedRow , 5);

                }
                else
                {


                    while(rowToMoveUp <= rowsInTable-1)
                    {

                        supplierTable3.setValueAt(supplierTable3.getValueAt(rowToMoveUp, 0), selectedRow, 0);            
                        supplierTable3.setValueAt(supplierTable3.getValueAt(rowToMoveUp, 1), selectedRow, 1);
                        supplierTable3.setValueAt(supplierTable3.getValueAt(rowToMoveUp, 2), selectedRow, 2);
                        supplierTable3.setValueAt(supplierTable3.getValueAt(rowToMoveUp, 3), selectedRow, 3);
                        supplierTable3.setValueAt(supplierTable3.getValueAt(rowToMoveUp, 4), selectedRow, 4);
                        supplierTable3.setValueAt(supplierTable3.getValueAt(rowToMoveUp, 5), selectedRow, 5);
                        rowToMoveUp++;
                        selectedRow++;
                    }
                }
            }
        }
        } catch (Exception e) {
          System.out.println(e.getMessage());
          controllingFrame = this;
          JOptionPane.showMessageDialog(controllingFrame, "Selected row is empty. Cant be deleted","Empty row", JOptionPane.INFORMATION_MESSAGE);
        }  
   
                    
    }//GEN-LAST:event_deleteSupplierButton5ActionPerformed

    private void orderTabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_orderTabelMouseClicked
        updateItemPanel();
    }//GEN-LAST:event_orderTabelMouseClicked

    private void orderTabelKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_orderTabelKeyReleased
        updateItemPanel();
    }//GEN-LAST:event_orderTabelKeyReleased

    private void updateItemPanel()
    {
                int selectedRow = orderTabel.getSelectedRow();
        
        if(orderTabel.getValueAt(selectedRow, 1) != null)
        {
            String barcode = (String) orderTabel.getValueAt(selectedRow, 1);
            barcodeLabel.setText("Barcode: " + orderController.findItemByBarcode(barcode).getBarcode());
            itemLabel.setText("Item nb: " + orderController.findItemByBarcode(barcode).getItemNumber());
            nameLabel.setText("Name: " + orderController.findItemByBarcode(barcode).getName());
            locationLabel.setText("Location: " + orderController.findItemByBarcode(barcode).getLocationsNumber());
            priceLabel.setText("Price: " + orderController.findItemByBarcode(barcode).getSellingPrice());
            discountLabel.setText("Discount: " + orderController.findItemByBarcode(barcode).getDiscount());
            inStockLabel.setText("In stock: " + orderController.findItemByBarcode(barcode).getAmountInStock());
        }
        else
        {
            barcodeLabel.setText("Barcode: ");
            itemLabel.setText("Item nb: ");
            nameLabel.setText("Name: ");
            locationLabel.setText("Location: ");
            priceLabel.setText("Price: ");
            discountLabel.setText("Discount: ");
            inStockLabel.setText("In stock: ");
        }
    }
    private void deleteItemButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteItemButton1ActionPerformed
        try {
          String newString = (String)ItemTable2.getValueAt(ItemTable2.getSelectedRow(), 0);
          itemController.deleteItem(newString);
          
        int rowsInTable = ItemTable2.getRowCount();
        int selectedRow = ItemTable2.getSelectedRow();
        int rowToMoveUp = selectedRow +1;
        if(ItemTable2.getSelectedRow() == -1)
        {
            controllingFrame = this;
            JOptionPane.showMessageDialog(controllingFrame, "No item is selected","Not selected", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            if(ItemTable2.getValueAt(selectedRow, 0) != null)
            {
                if(selectedRow == rowsInTable-1)
                {
                    ItemTable2.setValueAt(null, selectedRow , 0);
                    ItemTable2.setValueAt(null, selectedRow , 1);
                    ItemTable2.setValueAt(null, selectedRow , 2);
                    ItemTable2.setValueAt(null, selectedRow , 3);
                    ItemTable2.setValueAt(null, selectedRow , 4);
                    ItemTable2.setValueAt(null, selectedRow , 5);
                    ItemTable2.setValueAt(null, selectedRow , 6);
                    ItemTable2.setValueAt(null, selectedRow , 7);
                    ItemTable2.setValueAt(null, selectedRow , 8);
                    ItemTable2.setValueAt(null, selectedRow , 9);
                    ItemTable2.setValueAt(null, selectedRow , 10);
                    ItemTable2.setValueAt(null, selectedRow , 11);
                    ItemTable2.setValueAt(null, selectedRow , 12);
                    

                }
                else
                {


                    while(rowToMoveUp <= rowsInTable-1)
                    {

                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 0), selectedRow, 0);            
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 1), selectedRow, 1);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 2), selectedRow, 2);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 3), selectedRow, 3);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 4), selectedRow, 4);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 5), selectedRow, 5);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 6), selectedRow, 6);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 7), selectedRow, 7);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 8), selectedRow, 8);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 9), selectedRow, 9);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 10), selectedRow, 10);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 11), selectedRow, 11);
                        ItemTable2.setValueAt(ItemTable2.getValueAt(rowToMoveUp, 12), selectedRow, 12);
                        rowToMoveUp++;
                        selectedRow++;
                    }
                }
            }
        }
        } catch (Exception e) {
          System.out.println(e.getMessage());
          controllingFrame = this;
          JOptionPane.showMessageDialog(controllingFrame, "Selected row is empty. Cant be deleted","Empty row", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_deleteItemButton1ActionPerformed

    private void seachButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seachButton1ActionPerformed
        try
        {
            
            int machineNo=Integer.parseInt(machineListTextField1.getText());
            int rows = 0;
            int columns = 0;
            if(rentalCon.findMachine(machineNo) != null) 
            {
                    machineListningjTable1.setValueAt(rentalCon.findMachine(machineNo).getName(), rows, columns);
                    columns++;
                    machineListningjTable1.setValueAt(rentalCon.findMachine(machineNo).getMachineNo(), rows, columns);
                    columns++;
                    machineListningjTable1.setValueAt(rentalCon.findMachine(machineNo).getMachineStatus(), rows, columns);
                    columns++;
                    machineListningjTable1.setValueAt(rentalCon.findMachine(machineNo).getPrice(), rows, columns);
                    columns++;
            }
        }
        catch(Exception e)
            {
             System.out.println(e.getMessage());
            }
    }//GEN-LAST:event_seachButton1ActionPerformed

    private void searchItemButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchItemButton1ActionPerformed
        try {
           
            //if(supplierController.findSupplier(searchSupplierTextField3.getText()) !=null)
            String newString = searchItemTextField2.getText();
                if(itemController.findItemByBarcode(newString).getBarcode().equals(newString))
                
                {
                    System.out.print("hej");
                    String name = itemController.findItemByBarcode(searchItemTextField2.getText()).getName();
                    String itemNumber = itemController.findItemByBarcode(searchItemTextField2.getText()).getItemNumber();
                    String locationNumber = itemController.findItemByBarcode(searchItemTextField2.getText()).getLocationsNumber();
                    double buyingPrice = itemController.findItemByBarcode(searchItemTextField2.getText()).getBuyingPrice();
                    double sellingPrice = itemController.findItemByBarcode(searchItemTextField2.getText()).getSellingPrice();
                    int discount = itemController.findItemByBarcode(searchItemTextField2.getText()).getDiscount();
                    int amountInStock = itemController.findItemByBarcode(searchItemTextField2.getText()).getAmountInStock();
                    String barcode = itemController.findItemByBarcode(searchItemTextField2.getText()).getBarcode();
                    String supplier = itemController.findItemByBarcode(searchItemTextField2.getText()).getSupplier().getName();
                    String description = itemController.findItemByBarcode(searchItemTextField2.getText()).getDescription();
                    int minStock = itemController.findItemByBarcode(searchItemTextField2.getText()).getMinStock();
                    int maxStock = itemController.findItemByBarcode(searchItemTextField2.getText()).getMaxStock();
                    int amountPrOrder = itemController.findItemByBarcode(searchItemTextField2.getText()).getAmountPrOrder();
               
                    ItemTable2.setValueAt(name, 0, 0);
                    ItemTable2.setValueAt(itemNumber, 0, 1);
                    ItemTable2.setValueAt(locationNumber, 0, 2);
                    ItemTable2.setValueAt(buyingPrice, 0, 3);
                    ItemTable2.setValueAt(sellingPrice, 0, 4);
                    ItemTable2.setValueAt(discount, 0, 5);
                    ItemTable2.setValueAt(amountInStock, 0, 6);
                    ItemTable2.setValueAt(barcode, 0, 7);
                    ItemTable2.setValueAt(supplier, 0, 8);
                    ItemTable2.setValueAt(description, 0, 9);
                    ItemTable2.setValueAt(minStock, 0, 10);
                    ItemTable2.setValueAt(maxStock, 0, 11);
                    ItemTable2.setValueAt(amountPrOrder, 0, 12);

                }

                 } catch (Exception e) {
                    System.out.println(e.getMessage());
                    controllingFrame = this;
                    JOptionPane.showMessageDialog(controllingFrame, "The item was not found","Info",JOptionPane.INFORMATION_MESSAGE);  
                 }
    }//GEN-LAST:event_searchItemButton1ActionPerformed

    private void ordersSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ordersSearchButtonActionPerformed
        clearTable(findOrdersTable);
        int columnID = findTitleTableColumn("ID",findOrdersTable);
        int columnDate = findTitleTableColumn("Date", findOrdersTable);
        int columnCustomersName = findTitleTableColumn("Customer name", findOrdersTable);
        int columnNbOfItems = findTitleTableColumn("Number of items", findOrdersTable);
        int columnStatus = findTitleTableColumn("Status", findOrdersTable);
        int columnTotal = findTitleTableColumn("Total", findOrdersTable);
        
        int id = 0;
        String date = "";
        String customersName = "";
        int numberOfItems = 0;
        String status = "";
        double totalPrice = 0;
        
        int rows = 0;
        try
        {
            if(ordersIDButton.isSelected())
            {
                int index = 0;
                boolean found = false;
                id = Integer.parseInt(ordersSearchTextfield.getText());
                while(index < orderController.listAllOrder().size() && !found)
                {
                    if(orderController.findOrder(id) != null)
                    {
                        found = true;
                        date = orderController.findOrder(id).getDate();
                        customersName = orderController.findOrder(id).getCustomersName();
                        numberOfItems = orderController.findOrder(id).getPartOrders().size();
                        status = orderController.findOrder(id).getStatus();
                        totalPrice = orderController.findOrder(id).getTotalPrice();
                        
                        findOrdersTable.setValueAt(id, rows, columnID);
                        findOrdersTable.setValueAt(date, rows, columnDate);
                        if(orderController.findOrder(id).getPerson() != null){
                        findOrdersTable.setValueAt("R: " + orderController.findOrder(id).getPerson().getName(), rows, columnCustomersName);
                        }else{
                        findOrdersTable.setValueAt("U: " + customersName, rows, columnCustomersName);
                        }
                        findOrdersTable.setValueAt(numberOfItems, rows, columnNbOfItems);
                        findOrdersTable.setValueAt(status, rows, columnStatus);
                        findOrdersTable.setValueAt(totalPrice, rows, columnTotal); 
                    }
                    else
                    {
                        index++;
                    }
                }
                
            }
            else
            {
                String searchName = ordersSearchTextfield.getText();
                int index0 = 0;
                while(index0 < orderController.findOrderByName(searchName).size())
                {
                    id = orderController.findOrderByName(searchName).get(index0).getId();
                    customersName = searchName;
                    numberOfItems = orderController.findOrder(id).getPartOrders().size();
                    status = orderController.findOrder(id).getStatus();
                    totalPrice = orderController.findOrder(id).getTotalPrice();
                    
                    findOrdersTable.setValueAt(id, rows, columnID);
                    findOrdersTable.setValueAt(date, rows, columnDate);
                        if(orderController.findOrder(id).getPerson() != null){
                        findOrdersTable.setValueAt("R: " + orderController.findOrder(id).getPerson().getName(), rows, columnCustomersName);
                        }else{
                        findOrdersTable.setValueAt("U: " + customersName, rows, columnCustomersName);
                        }
                    findOrdersTable.setValueAt(numberOfItems, rows, columnNbOfItems);
                    findOrdersTable.setValueAt(status, rows, columnStatus);
                    findOrdersTable.setValueAt(totalPrice, rows, columnTotal);
                    
                    rows++;
                    index0++;
                }
            }       
        }
        
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }//GEN-LAST:event_ordersSearchButtonActionPerformed

    private void showAllOrdersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAllOrdersButtonActionPerformed
        int index = 0;
        int rowNb = 0;
        int columnID = findTitleTableColumn("ID",findOrdersTable);
        int columnDate = findTitleTableColumn("Date", findOrdersTable);
        int columnCustomersName = findTitleTableColumn("Customer name", findOrdersTable);
        int columnNbOfItems = findTitleTableColumn("Number of items", findOrdersTable);
        int columnStatus = findTitleTableColumn("Status", findOrdersTable);
        int columnTotal = findTitleTableColumn("Total", findOrdersTable);
        
        while(index < orderController.listAllOrder().size()) 
        {
            int id = orderController.listAllOrder().get(index).getId();
            String date = orderController.listAllOrder().get(index).getDate();
            String customersName = orderController.listAllOrder().get(index).getCustomersName();
            int numberOfItems = orderController.listAllOrder().get(index).getPartOrders().size();
            String status = orderController.listAllOrder().get(index).getStatus();
            double total = orderController.listAllOrder().get(index).getTotalPrice();
            
            
            findOrdersTable.setValueAt(id, rowNb, columnID);
            findOrdersTable.setValueAt(date, rowNb, columnDate);
            try{
                        if(orderController.findOrder(id).getPerson() != null){
                        findOrdersTable.setValueAt("R: " + orderController.findOrder(id).getPerson().getName(), rowNb, columnCustomersName);
                        }else{
                        findOrdersTable.setValueAt("U: " + customersName, rowNb, columnCustomersName);
                        }
            }catch(Exception e){
                System.out.println(e.getMessage());
            }
            findOrdersTable.setValueAt(numberOfItems, rowNb, columnNbOfItems);
            findOrdersTable.setValueAt(status, rowNb, columnStatus);
            findOrdersTable.setValueAt(total, rowNb, columnTotal);
            
            rowNb++;
            index++;
        }
    }//GEN-LAST:event_showAllOrdersButtonActionPerformed

    private void orderItemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderItemButtonActionPerformed
        ItemOrderGUI itemOrderGUI;
        itemOrderGUI = new ItemOrderGUI(loginGUI);
        //start i midten af skærmen.
        itemOrderGUI.setBounds(loginGUI.getWidthStartWindow(), loginGUI.getHeightStartWindow(), 1050,650);
        itemOrderGUI.setVisible(true);
        itemOrderGUI.itemWhichHaveBeenOrdered();
        itemOrderGUI.itemWhichHaveToBeOrdered();
    }//GEN-LAST:event_orderItemButtonActionPerformed

    private void updateStockButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateStockButtonActionPerformed
        UpdateStockGUI updateStockGUI;
        updateStockGUI = new UpdateStockGUI();
        updateStockGUI.setBounds((loginGUI.getWidthStartWindow()+(1050/2)-(400/2)), loginGUI.getHeightStartWindow()+(600/2)-(250/2), 300,250);
        updateStockGUI.setVisible(true);
    }//GEN-LAST:event_updateStockButtonActionPerformed

    private void ordersClearTableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ordersClearTableButtonActionPerformed
        clearTable(findOrdersTable);
    }//GEN-LAST:event_ordersClearTableButtonActionPerformed

    private void ordersDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ordersDeleteButtonActionPerformed
        try
        {
            int columnID = findTitleTableColumn("ID", findOrdersTable);
            int rowSelected = findOrdersTable.getSelectedRow();
            int id = (Integer) findOrdersTable.getValueAt(rowSelected, columnID);

            orderController.deleteOrder(id);
            System.out.println("Order is deleted");
            clearTable(findOrdersTable);
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }//GEN-LAST:event_ordersDeleteButtonActionPerformed

    private void registredButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_registredButtonActionPerformed

        jPanel7.setVisible(true);
    }//GEN-LAST:event_registredButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        try{

        Order order = orderController.findOrder(Integer.parseInt(idField.getText()));
        if( order != null){
            order.setPerson(personController.findPerson(Integer.parseInt(txtPhoneNo.getText())));
            JOptionPane.showMessageDialog(controllingFrame, "A Customer has been attached to the order","Customer Attached", JOptionPane.INFORMATION_MESSAGE);
        }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(controllingFrame, "Not found","Not found", JOptionPane.WARNING_MESSAGE);


    }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void updateItemButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateItemButton1ActionPerformed
        if(ItemTable2.getSelectedColumnCount() == 0){
            JOptionPane.showMessageDialog(controllingFrame, "No item selected","Not found", JOptionPane.WARNING_MESSAGE);
        }else{

        String getCell = (String)ItemTable2.getValueAt(ItemTable2.getSelectedRow(), 7);

        try{


        if(itemController.findItemByBarcode(getCell) != null){

            UpdateItem updateItemGUI = new UpdateItem(itemController.findItemByBarcode(getCell));
            if(!loginName.equals("manager"))
            {
                updateItemGUI.setSellBuyDiscountPriceFieldsFalse();
            }
            updateItemGUI.setVisible(true);
            
        }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(controllingFrame, "Not found","Not found", JOptionPane.WARNING_MESSAGE);

    }
    }
    }//GEN-LAST:event_updateItemButton1ActionPerformed
// Bruges til at finde kolonne nummer som svarer til den title man søger efter.
    private int findTitleTableColumn(String title, JTable table)
    {
        int columns = table.getColumnCount();
        int index = 0;
        int place = -1;
        while(index < columns && place < 0)
        {
            if(table.getColumnName(index).equals(title))
            {
                place = index;
            }
            index++;
        }
        return place;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new LoginGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable ItemTable2;
    private javax.swing.JRadioButton UnregistredButton;
    private javax.swing.JLabel VATLabel;
    private javax.swing.JRadioButton barcodeButton;
    private javax.swing.ButtonGroup barcodeItemNumberbuttonGroup3;
    private javax.swing.JLabel barcodeLabel;
    private javax.swing.JRadioButton barcodeRadioButton1;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JButton cancelOrderButton;
    private javax.swing.JButton changeStatusButton2;
    private javax.swing.JButton createItemButton1;
    private javax.swing.JButton createMachineButton4;
    private javax.swing.JButton createOrderButton;
    private javax.swing.JButton createSupplierButton5;
    private javax.swing.JTextField customersName1Field;
    private javax.swing.JLabel customersName1Label;
    private javax.swing.JButton customersNameButton;
    private javax.swing.JPanel customersNamePanel;
    private javax.swing.JLabel dateLabel;
    private javax.swing.JButton deleteItemButton;
    private javax.swing.JButton deleteItemButton1;
    private javax.swing.JButton deleteMachineButton5;
    private javax.swing.JButton deleteSupplierButton5;
    private javax.swing.JLabel discountLabel;
    private javax.swing.JSeparator findItemItemdetailsSeparator;
    private javax.swing.JTable findOrdersTable;
    private javax.swing.JButton findPersonButton;
    private javax.swing.JTextField idField;
    private javax.swing.JLabel inStockLabel;
    private javax.swing.JLabel infoDeleteLabel;
    private javax.swing.JLabel itemDetailsLabel;
    private javax.swing.JLabel itemLabel;
    private javax.swing.JRadioButton itemNumberButton;
    private javax.swing.JRadioButton itemNumberRadioButton1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JTextField jPhoneTxt;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTabbedPane jTabbedPane4;
    private javax.swing.JTable jTable2;
    private javax.swing.JLabel locationLabel;
    private javax.swing.JButton logOutButton;
    private javax.swing.JLabel loggedInAsLabel;
    private javax.swing.JTextField machineListTextField1;
    private javax.swing.JTable machineListningjTable1;
    private javax.swing.JPanel mainMenuPanel;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JLabel noNameLabel;
    private javax.swing.JLabel orderIDLabel;
    private javax.swing.JButton orderItemButton;
    private javax.swing.JLabel orderSentLabel;
    private javax.swing.JTable orderTabel;
    private javax.swing.JButton ordersClearTableButton;
    private javax.swing.JRadioButton ordersCustomersNameButton;
    private javax.swing.JButton ordersDeleteButton;
    private javax.swing.JRadioButton ordersIDButton;
    private javax.swing.JButton ordersSearchButton;
    private javax.swing.JPanel ordersSearchPanel;
    private javax.swing.JTextField ordersSearchTextfield;
    private javax.swing.JLabel priceLabel;
    private javax.swing.JRadioButton registredButton;
    private javax.swing.JButton saleCancelOrderButton;
    private javax.swing.JLabel saleCustomersNameLabel;
    private javax.swing.JLabel saleDateLabel;
    private javax.swing.JButton saleOKButton;
    private javax.swing.JLabel saleOrderIDLabel;
    private javax.swing.JTable saleOrderTabel;
    private javax.swing.JButton salePayButton;
    private javax.swing.JLabel saleStatusLabel;
    private javax.swing.JLabel saleStatusOnOrderLabel;
    private javax.swing.JLabel saleTotalPriceLabel;
    private javax.swing.JLabel saleTotalPriceNoVATLabel;
    private javax.swing.JLabel saleVATLabel;
    private javax.swing.JButton seachButton1;
    private javax.swing.JButton searchButton;
    private javax.swing.JTextField searchField;
    private javax.swing.JButton searchItemButton1;
    private javax.swing.JPanel searchItemPanel3;
    private javax.swing.JTextField searchItemTextField2;
    private javax.swing.JButton searchSupplierButton5;
    private javax.swing.JTextField searchSupplierTextField3;
    private javax.swing.JButton showAllOrdersButton;
    private javax.swing.JPanel showItemPanel3;
    private javax.swing.JTable supplierTable3;
    private javax.swing.JPanel tabOrderEnterCustomersNamePanel;
    private javax.swing.JPanel tabOrderFindItemPanel;
    private javax.swing.JPanel tabOrderPanel;
    private javax.swing.JPanel tabOrders;
    private javax.swing.JPanel tabPersonPanel;
    private javax.swing.JPanel tabRentMachines;
    private javax.swing.JPanel tabSalePanel;
    private javax.swing.JPanel tabStockItemPanel;
    private javax.swing.JTabbedPane tabSupplierPanel;
    private javax.swing.JLabel totalPriceLabel;
    private javax.swing.JLabel totalPriceNoVATLabel;
    private javax.swing.JTextField txtPhoneNo;
    private javax.swing.JButton updateItemButton1;
    private javax.swing.JButton updateMachineButton3;
    private javax.swing.JButton updateStockButton;
    private javax.swing.JButton updateSupplierAddressButton5;
    private javax.swing.JButton updateSupplierDeliveryPhoneButton5;
    // End of variables declaration//GEN-END:variables

}
